<?php
class omeauto_autoconfirm_branch_area{
    var $name = "收货地址所属区域仓库";
    
    function get_branch($order_sdf,$branch_list){
        if($order_sdf['consignee']['area']){
            $oBranch_area = &app::get('ome')->model('branch_area');
            $oRegion = &app::get('ectools')->model('regions');
            $consignee_area = $order_sdf['consignee']['area'];
            
            if(substr_count($consignee_area,":") == 2){
                list($package,$region_name,$region_id) = explode(':',$consignee_area);
            }else{
                $area = explode("/",$consignee_area);
                $area_node = array_pop($area);
                $region = $oRegion->dump(array('local_name'=>$area_node),"region_id");
                $region_id = $region['region_id'];
            }
            
            if($region_id){
                $region_info = $oRegion->dump($region_id);
                $region_path = explode(",",$region_info['region_path']);
                array_shift($region_path);
                array_pop($region_path);
                array_pop($region_path);
                
                $branch_area = $oBranch_area->getList("branch_id",array("branch_id"=>$branch_list,"region_id"=>$region_path),0,-1);
                if($branch_area){
                    $ret = array();
                    foreach($branch_area as $v){
                        if(!in_array($v['branch_id'],$ret)){
                            $ret[] = $v['branch_id'];
                        }
                    }
                    return $ret;
                }else{
                    return array();
                }
            }else{
                return array();
            }
        }else{
            return array();
        }
    }
    
}